import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './stores'
import axios from '@/libs/axios'
import mixins from '@/libs/mixins'
import directives from '@/directive'
import filters from '@/libs/filters'
import ls from '@/libs/vueStore'
import { NavBar, Toast, Dialog, Tabbar, TabbarItem, Divider, Tag, Field, Checkbox, CheckboxGroup, Button, Icon, Cell, CellGroup, Picker, Popup, Tab, Tabs, Lazyload, SwipeCell, Swipe, SwipeItem, NoticeBar } from 'vant'
import { toast } from '@/components/toast'
import { loading } from '@/components/loading'
import { getImgUrl } from '@/libs/utils'
import '@/styles/index.less'
import '@/styles/fonts/iconfont.js'
import PageLoading from '@/components/layout/PageLoading.vue'
import PageHeader from '@/components/layout/PageHeader.vue'
// import 'font-awesome/css/font-awesome.css'
import VueClipboard from 'vue-clipboard2'
import FastClick from '@/libs/fastclick'

Vue.config.productionTip = false

Vue.mixin(mixins)
Vue.use(directives)
Vue.use(ls)
Toast.setDefaultOptions = {
    duration: 1500
}
Vue.component(PageLoading.name, PageLoading)
Vue.component(PageHeader.name, PageHeader)
Vue.use(Button)
Vue.use(Icon)
Vue.use(NavBar)
Vue.use(Toast)
Vue.use(Dialog)
Vue.use(Divider)
Vue.use(Tag)
Vue.use(Checkbox).use(CheckboxGroup)
Vue.use(Field)
Vue.use(Cell).use(CellGroup)
Vue.use(Picker)
Vue.use(Popup)
// Vue.use(List)
Vue.use(Tab)
Vue.use(Tabs)
// Vue.use(Search)
Vue.use(Lazyload)
Vue.use(SwipeCell)
Vue.use(Swipe).use(SwipeItem)
// Vue.use(Tag)
Vue.use(Tabbar).use(TabbarItem)
// Vue.use(Overlay)
// Vue.use(Rate)
// Vue.use(ActionSheet)
// Vue.use(Uploader)
// Vue.use(Pagination)
Vue.use(NoticeBar)
// Vue.use(NumberKeyboard)

Vue.use(VueClipboard)

Vue.prototype.$http = axios
Vue.prototype.$Toast = Toast
Vue.prototype.$toast = toast
Vue.prototype.$loading = loading
Vue.prototype.$imgFile = getImgUrl

Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

// store 恢复
if (sessionStorage.getItem('VUEX_STORE')) {
    store.replaceState(Object.assign(store.state, JSON.parse(sessionStorage.getItem('VUEX_STORE'))))
    sessionStorage.removeItem('VUEX_STORE')
}

// 页面刷新或离开
window.onunload = function () {
    // 过滤微信store 兼容ios刷新后签名取刷新后的地址
    store.commit('wechat/clearSignUrl')
    sessionStorage.setItem('VUEX_STORE', JSON.stringify(store.state))
}

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')

FastClick.attach(document.body)
